package com.example.makerspace.controller;

import com.alibaba.fastjson.JSONObject;
import com.dtflys.forest.annotation.Get;
import com.example.makerspace.aop.Log;
import com.example.makerspace.dto.*;
import com.example.makerspace.service.AdminService;
import com.example.makerspace.utils.FileUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * @author River
 * @version 1.0
 * @date 2023/10/7 16:57
 * @description:
 */

@Controller
@ResponseBody
@RequestMapping("/api/manger")
@Api(tags = "后台管理员模块")
public class AdminController {
    @Resource
    private AdminService adminService;

  private  final  static  String   testHttpPrefix="https://119.45.199.13:3035/static/";
   private  final  static  String  devHttpPrefix="https://nism.ytcata.com:443/static/";

    @PostMapping("/edit")
    public Result edit(@RequestBody Map<String, Object> params) {
        return adminService.edit(params);
    }

    @PostMapping("/list")
    public Result list(@RequestBody PageRequest pageRequest) {
        return adminService.list(pageRequest);
    }

    @PostMapping("/userList")
    public PageResult userList(@RequestBody PageRequest pageRequest) {
        return adminService.userList(pageRequest);
    }

    @PostMapping("/applicationFormList")
    public PageResult applicationFormList(@RequestBody PageRequest pageRequest) {
        return adminService.applicationFormList(pageRequest);
    }
    @ApiOperation(value="下载附件接口",notes ="下载附件说明")
    @GetMapping("/download")
    public void download(HttpServletResponse response, @RequestParam String filePath) {
        FileUtils.downloadFile(response, devHttpPrefix+ filePath);
    }

    @PostMapping("/editDemand")
    public Result addDemand(@ModelAttribute DemandDTO demandDTO) {
        return adminService.editDemand(demandDTO);
    }

    @PostMapping("/editTechnic")
    public Result addTechnic(@ModelAttribute TechnicDTO technicDTO) {
        return adminService.editTechnic(technicDTO);
    }

    @PostMapping("/editCompany")
    public Result addCompany(@ModelAttribute CompanyDTO companyDTO) {
        return adminService.editCompany(companyDTO);
    }

    @PostMapping("/editUser")
    public Result editUser(@RequestBody UserDTO userDTO, HttpServletRequest httpServletRequest) {
        return adminService.editUser(userDTO, httpServletRequest);
    }

    @PostMapping("/editApplication")
    public Result editApplication(@ModelAttribute ApplicationDTO applicationDTO) {
        return adminService.editApplication(applicationDTO);
    }

    @PostMapping("/deleteAttachment")
    public Result deleteAttachment(@RequestBody ApplicationDTO applicationDTO) {
        return adminService.deleteAttachment(applicationDTO);
    }

    @PostMapping("/editBook")
    public Result editBook(@ModelAttribute BookDTO bookDTO) {
        return adminService.editBook(bookDTO);
    }

    @PostMapping("/editBookChapter")
    public Result editBookChapter(@RequestBody BookChapterDTO bookChapterDTO) {
        return adminService.editBookChapter(bookChapterDTO);
    }

    @PostMapping("/bookDetail")
    public Result bookDetail(@RequestBody BookChapterDTO bookChapterDTO) {
        return adminService.bookDetail(bookChapterDTO);
    }

    @PostMapping("/editCourse")
    public Result editBook(@ModelAttribute CourseDTO courseDTO) {
        return adminService.editCourse(courseDTO);
    }

    @PostMapping("/editCourseVideo")
    public Result editCourseVideo(@ModelAttribute CourseVideoDTO courseVideoDTO) {
        return adminService.editCourseVideo(courseVideoDTO);
    }

    @PostMapping("/courseDetail")
    public Result courseDetail(@RequestBody CourseVideoDTO courseVideoDTO) {
        return adminService.courseDetail(courseVideoDTO);
    }

    @PostMapping("/editNews")
    public Result editNews(@ModelAttribute NewsDTO newsDTO) {
        return adminService.editNews(newsDTO);
    }

    @PostMapping("/editExam")
    public Result editBook(@ModelAttribute ExamDTO examDTO) {
        return adminService.editExam(examDTO);
    }

    @PostMapping("/editExamQuestion")
    public Result editExamQuestion(@RequestBody ExamQuestionDTO examQuestionDTO) {
        return adminService.editExamQuestion(examQuestionDTO);
    }

    @PostMapping("/examDetail")
    public Result examDetail(@RequestBody ExamQuestionDTO examQuestionDTO) {
        return adminService.examDetail(examQuestionDTO);
    }

    @PostMapping("/demandList")
    public PageResult demandList(@RequestBody PageRequest pageRequest) {
        return adminService.demandList(pageRequest);
    }

    @PostMapping("/technicList")
    public PageResult technicList(@RequestBody PageRequest pageRequest) {
        return adminService.technicList(pageRequest);
    }

    @PostMapping("/companyList")
    public PageResult companyList(@RequestBody PageRequest pageRequest) {
        return adminService.companyList(pageRequest);
    }

    @PostMapping("/bookList")
    public PageResult bookList(@RequestBody PageRequest pageRequest) {
        return adminService.bookList(pageRequest);
    }

    @PostMapping("/courseList")
    public PageResult courseList(@RequestBody PageRequest pageRequest) {
        return adminService.courseList(pageRequest);
    }

    @PostMapping("/examList")
    public PageResult examList(@RequestBody PageRequest pageRequest) {
        return adminService.examList(pageRequest);
    }

    @PostMapping("/newsList")
    public PageResult newsList(@RequestBody PageRequest pageRequest) {
        return adminService.newList(pageRequest);
    }

    @PostMapping("/editContactInfo")
    public Result editContactInfo(@RequestBody ContactInfoDTO contactInfoDTO) {
        return adminService.editContactInfo(contactInfoDTO);
    }

    @PostMapping("/contactInfoList")
    public PageResult contactInfoList(@RequestBody PageRequest pageRequest) {
        return adminService.contactInfoList(pageRequest);
    }

    @PostMapping("/editCategory")
    public Result editCategory(@RequestBody CategoryDTO categoryDTO) {
        return adminService.editCategory(categoryDTO);
    }



    @PostMapping("/categoryList")
    public Result categoryList(@RequestBody PageRequest pageRequest) {
        return adminService.categoryList(pageRequest);
    }



    @ApiOperation(value="上传文件",notes ="上传文件说明")
    @PostMapping("/upload")
    public JSONObject upload(@ModelAttribute ResourceDTO resourceDTO) {
        return adminService.upload(resourceDTO);
    }
    @ApiOperation(value="修改用户基本信息表",notes ="修改用户基本信息表说明")
    @PostMapping("/updateApplication")
    public  Result updateApplication(@ModelAttribute ApplicationV2DTO applicationV2DTO){
        return  adminService.updateApplication(applicationV2DTO);
    }


    @ApiOperation(value="删除用户基本信息表",notes ="删除用户基本信息表说明")
    @PostMapping ("/deleteApplication")
    public  Result  deleteApplication(@RequestBody ApplicationV2DTO applicationV2DTO){
        return  adminService.deleteApplication(applicationV2DTO.getId(),applicationV2DTO.getUsername(),applicationV2DTO.getCompetitionId());
    }
    @ApiOperation(value="展示产品信息",notes ="展示产品信息说明")
    @PostMapping("/listDemand")
    public  Result listDemand(@RequestBody PageRequest pageRequest){
        return  adminService.listDemand(pageRequest);
    }

    @Log("删除用户")
    @ApiOperation(value="删除某个用户所有信息",notes ="删除某个用户所有信息说明")
    @PostMapping("/deleteUser")
    public  Result  deleteUser(@RequestBody UserDTO userDTO){
        return  adminService.deleteUser(userDTO);
    }

    @Log("删除赛题")
    @ApiOperation(value="通过赛题id删除",notes ="通过赛题id删除说明")
    @PostMapping("/deleteByCompetitionId")
    public  Result deleteByCompetitionId(@RequestBody ApplicationV2DTO applicationV2DTO){
        return  adminService.deleteByCompetitionId(applicationV2DTO);
    }


    @ApiOperation(value="展示用户信息",notes ="展示用户信息说明")
    @PostMapping("/listUser")
    public  Result listUser(@RequestBody PageRequest pageRequest){
        return  adminService.listUser(pageRequest);
    }


    @ApiOperation(value="展示后台实名认证信息接口",notes ="展示后台实名认证信息接口说明")
    @GetMapping("/showAuthentication")
    public  Result showAuthentication(@RequestParam("username")String username){
        return  adminService.showAuthentication(username);
    }
    @ApiOperation(value="用户管理-用户信息列表",notes ="用户管理-用户信息列表")
    @PostMapping("/showUserList")
    public  Result showUserList(@RequestBody PageRequest pageRequest){
        return  adminService.showUserList(pageRequest);
    }
    @Log("修改用户信息")
    @ApiOperation(value="用户管理-用户编辑",notes ="用户管理-用户编辑")
    @PostMapping("/editUserList")
    public  Result editUserList(@RequestBody UserDTO userDTO){
        return  adminService.editUserList(userDTO);
    }

    @Log("重置密码")
    @ApiOperation(value="用户管理-重置密码",notes ="用户管理-重置密码")
    @PostMapping("/resetPassword")
    public  Result resetPassword(@RequestBody UserDTO userDTO){
        return  adminService.resetPassword(userDTO);
    }


    @ApiOperation(value="用户管理-新增用户",notes ="用户管理-新增用户")
    @PostMapping("/addUser")
    public  Result addUser(@RequestBody UserDTO userDTO){
        return  adminService.addUser(userDTO);
    }
    @ApiOperation(value="用户管理-在线用户管理",notes ="用户管理-重置密码")
    @PostMapping("/onlineUser")
    public  Result onlineUser(@RequestBody PageRequest pageRequest){
        return  adminService.onlineUser(pageRequest);
    }
    @ApiOperation(value="用户管理-更改用户状态",notes ="用户管理-更改用户状态")
    @PostMapping("/updateUserState")
    public  Result updateUserState(@RequestBody UserDTO userDTO){
        return  adminService.updateUserState(userDTO);
    }

    @ApiOperation(value="用户管理-修改用户权限",notes ="用户管理-修改用户权限")
    @PostMapping("/assignPermissions")
    public  Result assignPermissions(@RequestBody UserDTO userDTO){
        return  adminService.assignPermissions(userDTO);
    }

    @ApiOperation(value="用户管理-强制下线",notes ="用户管理-强制下线")
    @PostMapping("/forcedOffline")
    public  Result forcedOffline(@RequestBody UserDTO userDTO){
        return  adminService.forcedOffline(userDTO);
    }
    @ApiOperation(value="用户管理-个人实名认证审核",notes ="用户管理-个人实名认证审核")
    @PostMapping("/personalName")
    public  Result personalName(@RequestBody PageRequest pageRequest){
        return  adminService.personalName(pageRequest);
    }

    @ApiOperation(value="用户管理-企业实名认证审核",notes ="用户管理-企业实名认证审核")
    @PostMapping("/entAuthentication")
    public  Result entAuthentication(@RequestBody PageRequest pageRequest){
        return  adminService.entAuthentication(pageRequest);
    }

    @ApiOperation(value="企业库接口",notes ="企业库接口")
    @PostMapping("/entData")
    public  Result entData(@RequestBody PageRequest pageRequest){
        return  adminService.entData(pageRequest);
    }

    @ApiOperation(value="总概览-用户注册总数量",notes ="总概览-用户注册总数量")
    @GetMapping("/userRegistration")
    public  Result userRegistration(){
        return  adminService.userRegistration();
    }
    @ApiOperation(value="总概览-上架产品总数量",notes ="总概览-上架产品总数量")
    @GetMapping("/showProducts")
    public  Result showProducts(){
        return  adminService.showProducts();
    }

    @ApiOperation(value="总概览-企业实名数量",notes ="总概览-企业实名数量")
    @GetMapping("/entRealName")
    public  Result entRealName(){
        return  adminService.entRealName();
    }
    @ApiOperation(value="总概览-赛题报名总数量",notes ="总概览-赛题报名总数量")
    @GetMapping("/questionsRegistration")
    public  Result questionsRegistration(){
        return  adminService.questionsRegistration();
    }

    @ApiOperation(value="总概览-其他汇总",notes ="总概览-任务条数信息")
    @GetMapping("/otherShow")
    public  Result otherShow(){
        return  adminService.otherShow();
    }
    @ApiOperation(value="总概览-积分排名",notes ="总概览-积分排名")
    @GetMapping("/pointSort")
    public  Result pointSort(){
        return  adminService.pointSort();
    }
    @ApiOperation(value="总概览-表单统计",notes ="总概览-表单统计")
    @GetMapping("/showTableData")
    public  Result showTableData(){
        return  adminService.showTableData();
    }

    @ApiOperation(value="用户管理-用户操作日志",notes ="用户管理--用户操作日志")
    @PostMapping("/showUserOperate")
    public  Result showUserOperate(@RequestBody PageRequest pageRequest){
        return  adminService.showUserOperate(pageRequest);
    }

    @ApiOperation(value="消息通知-查询新闻公告",notes ="消息通知-新闻公告")
    @PostMapping("/getNewBulletin")
    public  Result newBulletin(@RequestBody PageRequest pageRequest){
        return  adminService.newBulletin(pageRequest);
    }
    @ApiOperation(value="消息通知-增加新闻公告",notes ="消息通知-新闻公告")
    @PostMapping("/addBulletin")
    public  Result addBulletin(@ModelAttribute NewsDTO newsDTO){
        return  adminService.addBulletin(newsDTO);
    }
    @ApiOperation(value="消息通知-修改新闻公告",notes ="消息通知-新闻公告")
    @PostMapping("/updateNewBulletin")
    public  Result updateNewBulletin(@ModelAttribute NewsDTO newsDTO){
        return  adminService.updateNewBulletin(newsDTO);
    }
    @ApiOperation(value="消息通知-删除新闻公告",notes ="消息通知-新闻公告")
    @GetMapping("/deleteNewBulletin")
    public  Result deleteNewBulletin(String id){
        return  adminService.deleteNewBulletin(id);
    }


    @ApiOperation(value="用户管理-公司详细信息",notes ="用户管理-公司详细信息")
    @GetMapping("/entDetail")
    public  Result entDetail(String name){
        return  adminService.entDetail(name);
    }

    @ApiOperation(value="开放竞赛-作品提交",notes ="用户管理-公司详细信息")
    @PostMapping("/submission")
    public  Result submission(@RequestBody  PageRequest pageRequest){
        return  adminService.submission(pageRequest);
    }

    /**
     * 产品的历史记录
     * @param productId
     * @return
     */
    @ApiOperation(value="产品的历史记录",notes ="产品的历史记录")
    @GetMapping("/showProductHistory")
    public  Result showProductHistory(Integer productId){
        return  adminService.showProductHistory(productId);
    }
}
